import { createRouter, createWebHashHistory } from "vue-router";
import footer from "@/views/footer.vue";
const routes = [
  // {
  //     path: "/",
  //     name: "home",
  //     components: {
  //         default: () => import("@/pages/home.vue"),
  //         footer
  //     }
  // },
  {
    //登录
    path: "/login",
    name: "login",
    components: {
      default: () => import("@/pages/login/index.vue"),
    }
  },
  {
    //注册
    path: "/register",
    name: "register",
    components: {
      default: () => import("@/pages/register/index.vue"),
    },
  },
  {
    //我要卖卡
    path: "/sellCard",
    name: "sellCard",
    components: {
      default: () => import("@/pages/home/sellCard.vue"),
    },
    meta:{power:true}
  },
  {
    path: "/home",
    name: "home",
    meta: {
      keepAlive: true
    },
    components: {
      default: () => import("@/pages/home/index.vue"),
      footer,
    },
  },
  /**
   * 钱包模块
   */
  {
    path: "/wallet",
    name: "wallet",
    components: {
      default: () => import("@/pages/wallet/index.vue"),
      footer,
    },
    mate: {
      power: true
    }
  },
  {
    path: "/identity", // 身份认证
    name: "identity",
    component: () => import("@/pages/wallet/identity.vue"),
  },
  {
    path: "/myCard", // 我的银行卡
    name: "myCard",
    component: () => import("@/pages/wallet/myCard.vue"),
  },
  {
    path: "/addCard", // 我的银行卡
    name: "addCard",
    component: () => import("@/pages/wallet/addCard.vue"),
  },
  {
    path: "/draw", // 提现记录
    name: "draw",
    component: () => import("@/pages/wallet/draw.vue"),
  },
  {
    path: "/withdraw", // 提现
    name: "withdraw",
    component: () => import("@/pages/wallet/withdraw.vue"),
  },
  {
    path: "/balance", // 余额记录
    name: "balance",
    component: () => import("@/pages/wallet/balance.vue"),
  },
  {
    path: "/myInte", // 我的积分
    name: "myInte",
    component: () => import("@/pages/wallet/integral/myInte.vue"),
  },
  {
    path: "/exchangeInte", // 我的积分
    name: "exchangeInte",
    component: () => import("@/pages/wallet/integral/exchangeInte.vue"),
  },
  /**
   * 我的订单
   */
  {
    path: "/order",
    components: {
      default: () => import("@/pages/order/index.vue"),
      footer,
    },
    meta:{power:true}
  },
   {
    path: "/orderDetail",
    components: {
      default: () => import("@/pages/order/detail.vue"),
    },
    meta:{power:true}
  },
  /**
   * 个人中心模块
   */
  {
    path: "/personal",
    components: {
      default: () => import("@/pages/personal/index.vue"),
      footer,
    },
    // meta:{power:true}
  },
  {
    //基本信息
    path: "/information",
    name: "information",
    components: {
      default: () => import("@/pages/personal/information/list.vue"),
    },
    meta:{power:true}
  },
  {
    //帮助中心
    path: "/help",
    name: "help",
    components: {
      default: () => import("@/pages/personal/help/index.vue"),
    },
  },
  {
    //帮助中心列表二级
    path: "/helplist",
    name: "helplist",
    components: {
      default: () => import("@/pages/personal/help/list.vue"),
    },
  },
  {
    //帮助中心详情
    path: "/helpdetail",
    name: "helpdetail",
    components: {
      default: () => import("@/pages/personal/help/detail.vue"),
    },
  },
  {
    //我的团队
    path: "/team",
    name: "team",
    components: {
      default: () => import("@/pages/personal/team/index.vue"),
    },
    meta:{power:true}
  },
  {
    //我的团队
    path: "/teamdetail",
    name: "teamdetail",
    components: {
      default: () => import("@/pages/personal/team/detail.vue"),
    },
    meta:{power:true}
  },
  {
    //绑定手机号
    path: "/bindtel",
    name: "bindtel",
    components: {
      default: () => import("@/pages/personal/bind/bindtel.vue"),
    },
    meta:{power:true}
  },
  {
    //绑定邮箱
    path: "/bindemail",
    name: "bindemail",
    components: {
      default: () => import("@/pages/personal/bind/bindemail.vue"),
    },
    meta:{power:true}
  },
  {
    //忘记密码
    path: "/forgatepassword",
    name: "forgatepassword",
    components: {
      default: () => import("@/pages/login/forgatepassword/index.vue"),
    },
  },
  {
    //设置登录密码
    path: "/loginpassword",
    name: "loginpassword",
    components: {
      default: () => import("@/pages/personal/password/loginpassword.vue"),
    },
    meta:{power:true}
  },
  {
    //设置支付密码
    path: "/paypassword",
    name: "paypassword",
    components: {
      default: () => import("@/pages/personal/password/paypassword.vue"),
    },
    meta:{power:true}
  },
  {
    //我的邀请
    path: "/invitation",
    name: "invitation",
    components: {
      default: () => import("@/pages/personal/invitation/index.vue"),
    },
    meta:{power:true}
  },
  {
    //设置昵称
    path: "/name",
    name: "name",
    components: {
      default: () => import("@/pages/personal/update/name.vue"),
    },
    meta:{power:true}
  },
  {
    //设置whatsappId
    path: "/whatsapp",
    name: "whatsapp",
    components: {
      default: () => import("@/pages/personal/update/whatsapp.vue"),
    },
    meta:{power:true}
  },
   {
    //提现详情
    path: "/payDetail",
    name: "payDetail",
    components: {
      default: () => import("@/pages/order/payDetail/index.vue"),
    },
    meta:{power:true}
  },
  {
    //通知中心
    path: "/notic",
    name: "notic",
    components: {
      default: () => import("@/pages/home/notic/index.vue"),
    },
    meta:{power:true}
  },
  {
    //通知中心
    path: "/noticdetail",
    name: "noticdetail",
    components: {
      default: () => import("@/pages/home/notic/detail.vue"),
    },
  },
  {
    //语言设置
    path: "/setlanguage",
    name: "setlanguage",
    components: {
      default: () => import("@/pages/personal/setlanguage/index.vue"),
    },
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

router.beforeEach((to, from) => {
  console.log("进来之前了哦");
  console.log(to);
  console.log(to.meta.power && !Boolean(sessionStorage.getItem('_token')),'token');
  console.log(to.meta.power , sessionStorage.getItem('_token'));
  if (to.path == "/") {
    router.replace("/home");
    return true;
  } else if (to.path == "/register") {
    // router.replace("/login");
    console.log('123123',to)
     to.query.code?localStorage.setItem('myCode',to.query.code):''
    return true;
   } else if(to.meta.power && !Boolean(sessionStorage.getItem('_token'))){
    console.log(333)
    // router.replace("/login");
    return true;
  }
  console.log(from);
  // 路由守卫逻辑

  // 通过 return turn;
  // 不通过 return false;
  return true;
});

export default router;
